# Maintainer: Ray Donnelly <mingw.android@gmail.com>

_realname=graphviz
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.40.1
_commit='67cd2e5121379a38e0801cc05cce503' # stable_release_2.40.1
pkgrel=13
pkgdesc="Graph Visualization Software (mingw-w64)"
arch=('any')
url='https://www.graphviz.org/'
license=('EPL')
depends=("${MINGW_PACKAGE_PREFIX}-cairo"
         "${MINGW_PACKAGE_PREFIX}-devil"
         "${MINGW_PACKAGE_PREFIX}-expat"
         "${MINGW_PACKAGE_PREFIX}-freetype"
         "${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-gtk2"
         "${MINGW_PACKAGE_PREFIX}-gtkglext"
         "${MINGW_PACKAGE_PREFIX}-fontconfig"
         "${MINGW_PACKAGE_PREFIX}-freeglut"
         "${MINGW_PACKAGE_PREFIX}-libglade"
         "${MINGW_PACKAGE_PREFIX}-libgd"
         "${MINGW_PACKAGE_PREFIX}-libpng"
         "${MINGW_PACKAGE_PREFIX}-libsystre"
         "${MINGW_PACKAGE_PREFIX}-libwebp"
         "${MINGW_PACKAGE_PREFIX}-gts"
         "${MINGW_PACKAGE_PREFIX}-pango"
         "${MINGW_PACKAGE_PREFIX}-poppler"
         "${MINGW_PACKAGE_PREFIX}-zlib"
         "${MINGW_PACKAGE_PREFIX}-libtool")
makedepends=(#"${MINGW_PACKAGE_PREFIX}-ocaml"
             #"${MINGW_PACKAGE_PREFIX}-lua"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             #"${MINGW_PACKAGE_PREFIX}-python"
             #"${MINGW_PACKAGE_PREFIX}-ruby"
             #"${MINGW_PACKAGE_PREFIX}-tcl"
             "${MINGW_PACKAGE_PREFIX}-zlib"
             "git")
options=(libtool)
install=${_realname}-${CARCH}.install
source=(${_realname}-${pkgver}::git+https://gitlab.com/graphviz/graphviz.git#commit=${_commit}
        #https://graphviz.gitlab.io/pub/graphviz/stable/SOURCES/graphviz.tar.gz
        #"https://www.graphviz.org/pub/${_realname}/stable/SOURCES/${_realname}-${pkgver}.tar.gz"
        001-msvc-pragma.patch.patch
        002-no-undefined-and-def-files.patch
        003-fix-dependency-detect.patch
        004-exports.patch
        005-plugin-exports.patch
        006-missing-libs.patch
        007-dont-export-libtool-symbols.patch
        008-fix-dll-names-in-def.patch
        009-fix-warnings.patch
        010-no-extern-time.patch)
sha256sums=('SKIP'
            'f64a7c0fdfd15aedc8cf31c39c5017df1ac8e21f3ffa6f362e62952a8b990aef'
            '62c4a7c92b6400a836ee5ee8f669d9ca57c457e82b74cd4af2c6537a72a61b5c'
            '125ab01113fb39b8c42ab65a6e286193deb565171269462e764dbfe2ef78aeec'
            '4d8b322664411bd82356825c9798b94b2843618134e9bcb8ad8bb1f138d6bc37'
            '1b4ca68365a14c926fd42a20b7ee094eda7f4747a05af302fc109f66fab5e528'
            'f90d3e43d3bb3b16a576ed9f4158498b0d6579c08f2f93d664a530d2097bda43'
            '99616247f4dabb22df1b031e2de873706deeaf9d5e868b1b3b9e9a784d61b12d'
            '8500ac206bab3d103983d8c20d09152a15f40b5229c9620a8c68447f9e9e72ed'
            'b4906b306ed03714a32fa89ca1871f7fe04fc7fe534969b32b48e9687be39da0'
            '36aad4169c7680ac22fc6a52cf7dbf6e01afd4525f4863a8fd0785a2d22d825a')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-msvc-pragma.patch.patch
  patch -p1 -i ${srcdir}/002-no-undefined-and-def-files.patch
  patch -p1 -i ${srcdir}/003-fix-dependency-detect.patch
  patch -p1 -i ${srcdir}/004-exports.patch
  patch -p1 -i ${srcdir}/005-plugin-exports.patch
  patch -p1 -i ${srcdir}/006-missing-libs.patch
  patch -p1 -i ${srcdir}/007-dont-export-libtool-symbols.patch
  patch -p1 -i ${srcdir}/008-fix-dll-names-in-def.patch
  patch -p1 -i ${srcdir}/009-fix-warnings.patch
  patch -p1 -i ${srcdir}/010-no-extern-time.patch

  ./autogen.sh NOCONFIG
}

build() {
  local gd_incdir=$(pkg-config --variable=includedir gdlib)
  CFLAGS+=" -Wno-sign-conversion -Wno-sign-compare -Wno-conversion"
  CXXFLAGS+=" -Wno-sign-conversion -Wno-sign-compare -Wno-conversion"
  CFLAGS+=" -fcommon"  # GCC10 is stricter, change to the previous default
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-guile=no \
    --enable-perl=no \
    --enable-php=no \
    --enable-ocaml=no \
    --enable-tcl=no \
    --enable-ruby=no \
    --enable-python=no \
    --enable-lua=no \
    --enable-r=no \
    --enable-sharp=no \
    --enable-swig=no \
    --enable-java=no \
    --with-webp=yes \
    --with-gdincludedir=${gd_incdir} \
    --enable-shared \
    --disable-static

  make
}

check() {
  cd "${srcdir}"/build-${CARCH}
  make check
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make install DESTDIR="${pkgdir}"
}
